﻿using System;
namespace RapidRepository.Context
{
    /// <summary>
    /// Stores data required for an operation.
    /// </summary>
    public class OperationRequest
    {
        #region Properties

        /// <summary>
        /// Gets or sets the entity id.
        /// </summary>
        /// <value>The entity id.</value>
        public Guid EntityId { get; private set; }

        /// <summary>
        /// Gets or sets the entity.
        /// </summary>
        /// <value>The entity.</value>
        public object Entity { get; private set; }
        
        /// <summary>
        /// Gets or sets the type of the entity.
        /// </summary>
        /// <value>The type of the entity.</value>
        public Type EntityType { get; private set; }

        /// <summary>
        /// Gets or sets the type of the operation.
        /// </summary>
        /// <value>The type of the operation.</value>
        public OperationRequestType OperationRequestType { get; private set; } 

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="OperationRequest"/> class.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="operationRequestType">Type of the operation request.</param>
        public OperationRequest(object entity, Type entityType, OperationRequestType operationRequestType)
        {
            Contract.Requires("entity", entity != null);
            Contract.Requires("entityType", entityType != null);

            if (operationRequestType != Context.OperationRequestType.Add)
            {
                this.EntityId = ((IRapidEntity)entity).Id;
            }

            this.Entity = entity;
            this.EntityType = entityType;            
            this.OperationRequestType = operationRequestType;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OperationRequest"/> class.
        /// </summary>
        /// <param name="entityId">The entity id.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="operationRequestType">Type of the operation request.</param>
        public OperationRequest(Guid entityId, Type entityType, OperationRequestType operationRequestType)
        {
            Contract.Requires("entityId", entityId != Guid.Empty);
            Contract.Requires("entityType", entityType != null);

            this.EntityId = entityId;
            this.EntityType = entityType;
            this.OperationRequestType = operationRequestType;
        }

        #endregion
    }
}
